package com.itheima.mapper;

import com.itheima.entity.Dish;
import com.itheima.dto.DishDto;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface DishMapper {
    @Select("select count(*) from dish where category_id=#{categoryId}")
    long findDishCountById(long id);

    @Insert("insert into dish values(null,#{name},#{categoryId},#{price},#{code},#{image},#{description},#{status},#{sort},#{createTime},#{updateTime},#{createUser},#{updateUser},0)")
    //通知mybatis插入数据之后，把id列的值设置给实体类的id属性
    @Options(useGeneratedKeys = true, keyColumn = "id", keyProperty = "id")
    void save(DishDto dishDto);

    List<Dish> findByName(@Param("name") String name);

    @Select("select * from dish where id=#{id}")
    Dish findById(long id);

    void updateById(DishDto dishDto);

    //    @Select("select *from dish where category_id=#{id}")
//    List<Dish> findByCategoryId(long categoryId);

    List<Dish> findByCategoryId(@Param("categoryId") Long categoryId, @Param("status") Integer status);

    void deleteByIds(@Param("ids") List<Long> ids);

    //查找dish启动的数量
    long findStatusCount(@Param("ids") List<Long> ids);

    void status(@Param("status") Integer status, @Param("ids") List<Long> ids);

    List<Integer> findByDishStatus(@Param("dishList") List<Long> dishList);
}
